<template>
<!-- 滑动条区域 -->
  <div class="container">
    <div id="slider" class="mui-slider">
      <div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
        <div class="mui-scroll">
          <a :class="['mui-control-item', item.id === 0 ? 'mui-active' : '']" v-for="item in photolist" :key="item.id" @click="getPhotoById(item.id)">
            {{item.title}}
          </a>
				</div>
			</div>
		</div>
    <!-- 图片列表 -->
    <ul class="photo-list">
      <router-link tag="li" :to="'/home/photoinfo/' + item.id" v-for="item in list" :key="item.id">
        <img v-lazy="item.img_url">
        <div class="info">
          <div class="title">
            <h1>{{item.title}}</h1>
          </div>
          <div class="zhaiyao">
            {{item.zhaiyao}}
          </div>
        </div>
      </router-link>
    </ul>
  </div>
</template>

<script>
  //导入mui的js文件
  import mui from '../../lib/mui/js/mui.min.js'
  //初始化滑动空间
  // mui('.mui-scroll-wrapper').scroll({deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
  // });
  export default {
    data() {
      return {
        photolist:[], //分类列表数组
        list: []
      };
    },
    created () {
      this.getPhotoList();
      this.getPhotoById(0);
      },
    mounted () {
        //初始化滑动空间
        //需要放到钩子函数中来 否则无法操作dom元素
      mui('.mui-scroll-wrapper').scroll({ deceleration: 0.0005 })
      },
    methods: {
      getPhotoList() {
        this.$http.get('api/getimgcategory').then(result => {
          if(result.body.status === 0){
            result.body.message.unshift({ title:'全部', id:0 });
            this.photolist = result.body.message;
          }
        });
      },
      getPhotoById(photoId) {
        //获取图片列表
        this.$http.get('api/getimages/' + photoId).then(result => {
          this.list = result.body.message;
        });
      }
    }
  }
</script>

<style lang="scss" scoped>
  * {
    touch-action: pan-y;
  }
  .photo-list {
    padding: 10px;
    margin: 0;
    padding-bottom: 5px;
    li {
      list-style: none;
      background-color: #ccc;
      text-align: center;
      margin-bottom: 5px;
      box-shadow: 0 0 6px #999;
      position: relative;
      img {
        width: 100%;
        vertical-align: middle;
      }
      img[lazy="loading"] {
        width: 40px;
        height: 300px;
        margin: auto;
      }
      .info {
        color: white;
        position: absolute;
        bottom: 0;
        text-align: left;
        background-color: rgba(0,0,0,0.4);
        max-height: 84px;
        h1 {
          font-size: 14px;
        }
        .zhaiyao {
          font-size: 13px;
        }
      }
    }
  }
</style>
